package testGUI;

import java.awt.Point;
import java.util.ArrayList;

import javax.swing.JLabel;

public class CollisionControl {

	private ArrayList<Point> stonePositions;
	private JLabel labelToMove;

	public CollisionControl(ArrayList<Point> positions, JLabel movingLabel) {
		stonePositions = positions;
		labelToMove = movingLabel;
	}

	public boolean noCollision(String direction) {

		switch (direction) {

		case ("RIGHT"):
			for (Point p : stonePositions) {
				if (p.getY() - 40 < labelToMove.getLocation().getY()
						&& p.getY() + 40 > labelToMove.getLocation().getY()
						&& p.getX() - 40 > labelToMove.getLocation().getX()) {
					return false;
				}
			}
			return true;

		case ("LEFT"):
			for (Point p : stonePositions) {
				if (p.getY() - 40 < labelToMove.getLocation().getY()
						&& p.getY() + 40 > labelToMove.getLocation().getY()
						&& p.getX() + 40 < labelToMove.getLocation().getX()) {
					return false;
				}
			}
			return true;

		case ("UP"):
			for (Point p : stonePositions) {
				if (p.getX() - 40 < labelToMove.getLocation().getX()
						&& p.getX() + 40 > labelToMove.getLocation().getX()
						&& p.getY() + 40 > labelToMove.getLocation().getY()) {
					return false;
				}
			}
			return true;

		case ("DOWN"):
			for (Point p : stonePositions) {
				if (p.getX() + 40 > labelToMove.getLocation().getX()
						&& p.getX() - 40 < labelToMove.getLocation().getX()
						&& p.getY() + 40 > labelToMove.getLocation().getY()) {
					return false;
				}
			}
			return true;

		}

		return false;
	}
}
